package com.spsy.order.controller;

import com.alibaba.fastjson2.JSON;
import com.spsy.api.common.AddOrderVo;
import com.spsy.common.core.domain.R;
import com.spsy.order.domain.OrderInfo;
import com.spsy.order.service.IOrderInfoService;
import com.spsy.pay.api.PayApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: liuzhiping
 * @date: 2025/10/24 19:08
 **/
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderOptsController {

    @Autowired
    private PayApi payApi;

    @Autowired
    private IOrderInfoService iOrderInfoService;

    private ExecutorService executorService = Executors.newFixedThreadPool(5);




    @GetMapping("/create2")
    public R test() throws Exception
    {

        return R.ok("success");

    };

    @PostMapping("/create")
    public R createOrder(@RequestBody  AddOrderVo vo) throws Exception
    {

        log.info(" 订单系统 参数：{} ", JSON.toJSONString(vo));






        int insertCount = this.iOrderInfoService.insertOrderInfo(OrderInfo.builder().orderStatus((long)1).orderSn(vo.getOrderId()).userId(Long.valueOf(vo.getUserId())).build());

        log.info("insertCount插入数据:{}",insertCount);





        //处理业务逻辑
        R r = this.payApi.payOrder(vo);

        int updateCount = this.iOrderInfoService.updateOrderInfo(OrderInfo.builder().orderSn(vo.getOrderId()).userRemark((String)r.getData()).build());


        log.info("updateCount修改数据:{}",updateCount);

        return r;

    };






}
